package com.zenithmind.document.pojo.domain;

import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableLogic;
import com.baomidou.mybatisplus.annotation.TableName;
import com.zenithmind.common.base.BaseEntity;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import lombok.EqualsAndHashCode;

/**
 * 文档评价实体类
 * 
 * @author ZenithMind Team
 * @since 2025-01-09
 */
@Data
@EqualsAndHashCode(callSuper = true)
@TableName("document_rating")
@Schema(description = "文档评价实体")
public class DocumentRating extends BaseEntity {

    /**
     * 文档ID
     */
    @TableField("document_id")
    @Schema(description = "文档ID")
    private String documentId;

    /**
     * 用户ID
     */
    @TableField("user_id")
    @Schema(description = "用户ID")
    private String userId;

    /**
     * 评分（1-5星）
     */
    @TableField("rating")
    @Schema(description = "评分（1-5星）")
    private Integer rating;

    /**
     * 评价内容
     */
    @TableField("comment")
    @Schema(description = "评价内容")
    private String comment;

    /**
     * 是否匿名（0-否，1-是）
     */
    @TableField("is_anonymous")
    @Schema(description = "是否匿名（0-否，1-是）")
    private Integer isAnonymous;

    /**
     * 状态（0:待审核, 1:已通过, 2:已拒绝）
     */
    @TableField("status")
    @Schema(description = "状态（0:待审核, 1:已通过, 2:已拒绝）")
    private Integer status;

    // ========== 静态工厂方法 ==========

    /**
     * 创建评分
     */
    public static DocumentRating createRating(String documentId, String userId, Double rating, String comment) {
        DocumentRating documentRating = new DocumentRating();
        documentRating.setDocumentId(documentId);
        documentRating.setUserId(userId);
        documentRating.setRating(rating != null ? rating.intValue() : null);
        documentRating.setComment(comment);
        documentRating.setIsAnonymous(0);
        documentRating.setStatus(1); // 默认已通过
        return documentRating;
    }

    // ========== 业务方法 ==========

    /**
     * 更新评分
     */
    public void updateRating(Double newRating, String newComment) {
        if (newRating != null) {
            this.rating = newRating.intValue();
        }
        if (newComment != null) {
            this.comment = newComment;
        }
    }

}
